import AbsolutePlugin from '../plugins/AbsolutePlugin';

export default class Store {
    private static instance: Store | null = null;
    private plugins: Map<string, AbsolutePlugin> = new Map();

    private constructor() {}

    /**
     * 获取 Store 单例
     */
    public static getInstance(): Store {
        if (!Store.instance) {
            Store.instance = new Store();
        }
        return Store.instance;
    }

    /**
     * 注册插件
     * @param name 插件名称
     * @param plugin 插件实例
     */
    public registerPlugin(name: string, plugin: AbsolutePlugin): void {
        if (this.plugins.has(name)) {
            throw new Error(`Plugin ${name} already exists`);
        }
        this.plugins.set(name, plugin);
    }

    /**
     * 获取插件
     * @param name 插件名称
     */
    public getPlugin<T extends AbsolutePlugin>(name: string): T | undefined {
        return this.plugins.get(name) as T | undefined;
    }

    /**
     * 移除插件
     * @param name 插件名称
     */
    public removePlugin(name: string): void {
        this.plugins.delete(name);
    }

    /**
     * 获取所有插件
     */
    public getAllPlugins(): Map<string, AbsolutePlugin> {
        return this.plugins;
    }
} 